Add property-based tests for API domain, policy, postage, receipt, id… - #1906
Merged
kryputh merged 1 commit intoJul 30, 2026
Merged
Conversation
…empotency, and repository invariants Introduces fast-check as a devDependency and a shared arbitraries module (tests/unit/api/arbitraries.ts) generating Stellar addresses, 32-byte hashes, i128-bounded amount strings, and UTC/offset timestamps that mirror the exact validation rules in src/server/api/domain.ts. New property suites exercise valid and invalid generated inputs across stellarAddressSchema, hash32Schema, stroopAmountSchema, mailboxPolicySchema, postageSchema, and receiptSchema (ordering + future-skew boundaries), plus behavioral invariants in evaluateMailboxPolicy, submitPostage, receipt delivery/read idempotency, idempotency key hashing/canonicalization/replay semantics, MemoryApiRepository round-trips and CAS races, and actor/delegation authorization. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add property-based tests for Stellar addresses, hashes, amounts, timestamps, policies, postage, and receipts
Problem
The unit suite in
tests/unit/apicovers actor, domain, request, response, policy, postage, receipt, idempotency, and memory-repository behavior with example-based tests. Example tests can miss malformed Unicode, numeric boundaries, timestamp combinations, and unexpected object shapes that hand-picked examples don't happen to cover.What this PR does
Adds
fast-checkas a devDependency and a shared arbitraries module (tests/unit/api/arbitraries.ts) that generates domain values mirroring the exact validation rules insrc/server/api/domain.ts:G[A-Z2-7]{55}addresses, whitespace/case-variant addresses that normalize correctly, and structurally invalid addresses (wrong prefix, wrong length, disallowed base32 characters).2^127 - 1), plus invalid variants (negative, one past the boundary, leading zeros, non-numeric).Z-suffixed instants (forpostage.createdAt/ idempotency records) versus offset-bearing instants (valid only for receipt fields), and receipt timestamp pairs that honor ordering + future-skew invariants.New property-test files (49 new tests total):
domain.properties.test.tspolicy-service.properties.test.tsevaluateMailboxPolicydecision table (allow/block/default rules) across arbitrary policy + postage + verification combinationspostage-service.properties.test.tssubmitPostageminimum-postage enforcement and duplicate-messageIdconflict, for arbitrary amountsreceipt-service.properties.test.tsidempotency-service.properties.test.tsmemory-repository.properties.test.tstransitionPostageCAS racesactor.properties.test.tsresponse.properties.test.tsvalidateCorrelationIdlength boundary and disallowed-character rejectionAcceptance criteria
fast-check's default failure output includes{ seed, path }plus a shrunk counterexample, so any CI failure can be reproduced locally by passing the same seed back intofc.assert.numRunsis capped per property (60–200), and the full suite (151 files / 1766 tests, including these additions) runs in ~25–30s locally.Verification
bun install(regeneratedbun.lockb/package-lock.jsonwith the newfast-checkdevDependency)npx vitest run tests/unit— 151 files passed, 1766 tests passed, 3 expected fail (pre-existing)npx tsc --noEmit— no errorsnpx eslint tests/unit/api/arbitraries.ts tests/unit/api/*.properties.test.ts— no errors{ seed, path }and shrunk counterexampleFiles changed
New:
tests/unit/api/arbitraries.tstests/unit/api/actor.properties.test.tstests/unit/api/domain.properties.test.tstests/unit/api/idempotency-service.properties.test.tstests/unit/api/memory-repository.properties.test.tstests/unit/api/policy-service.properties.test.tstests/unit/api/postage-service.properties.test.tstests/unit/api/receipt-service.properties.test.tstests/unit/api/response.properties.test.tsModified:
package.json(addedfast-checkdevDependency)package-lock.json,bun.lockbCloses #1553